<?php

declare(strict_types=1);

namespace Dreamcat\ApiDoc\Error;

use JetBrains\PhpStorm\ExpectedValues;
use JetBrains\PhpStorm\Pure;
use RuntimeException;
use Throwable;

/**
 * 保存器异常
 * @author vijay
 */
class SaverException extends RuntimeException
{
    /** @var int http请求状态码与预期不符 */
    public const UNEXPECT_HTTP_CODE = 2001001;
    /** @var int http消息体为空 */
    public const EMPTY_HTTP_BODY = 2001002;
    /** @var int http消息体不是有效的json */
    public const INVALID_JSON_HTTP_BODY = 2001003;
    /** @var int http异常 */
    public const HTTP_EXCEPTION = 2001004;
    /** @var int 业务状态码异常 */
    public const INVALID_BUSI_CODE = 2002001;

    /**
     * @param string $message 异常信息
     * @param int $code 异常码
     * @param ?Throwable $previous 异常链的前一异常
     */
    #[Pure]
    public function __construct(
        string $message,
        #[ExpectedValues(valuesFromClass: SaverException::class)]
        int $code,
        Throwable $previous = null
    ) {
        parent::__construct($message, $code, $previous);
    }
}

# end of file
